package com.feisuanyz.util;

import lombok.*;

/**
 * Restful API 返回结果类
 * @author 23265
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestResult {

    public static final String SUCCESS_CODE = "000000";
    public static final String FAILURE_CODE = "000001";

    private String code;
    private String msg;
    private Object data;

    /**
     * 成功返回结果
     * @param msg 提示信息
     * @param data 返回的数据
     * @return RestResult 结果对象
     */
    public static RestResult success(String msg, Object data) {
        return new RestResult(SUCCESS_CODE, msg, data);
    }

    /**
     * 成功返回结果
     * @param msg 提示信息
     * @return RestResult 结果对象
     */
    public static RestResult success(String msg) {
        return new RestResult(SUCCESS_CODE, msg, null);
    }

    /**
     * 失败返回结果
     * @param msg 提示信息
     * @return RestResult 结果对象
     */
    public static RestResult failure(String msg) {
        return new RestResult(FAILURE_CODE, msg, null);
    }
}